package com.xyht.sca_s.student_manage_system.modules.trainingSchool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.entity.SmsTsWorkerLevel;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.entity.resp.SmsTsWorkerLevelResp;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.mapper.SmsTsWorkerLevelMapper;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.service.SmsTsWorkerLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;

/**
 * <p>
 * 职工级别表 服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2024-05-15
 */
@Service
public class SmsTsWorkerLevelServiceImpl extends ServiceImpl<SmsTsWorkerLevelMapper, SmsTsWorkerLevel> implements SmsTsWorkerLevelService {

    @Override
    public ResponseResult list(Integer pageNum, Integer pageSize, String ss) {
        LambdaQueryWrapper<SmsTsWorkerLevel> queryWrapper = new LambdaQueryWrapper<SmsTsWorkerLevel>()
                .orderByAsc(SmsTsWorkerLevel::getCreateTime);

        if (!isNullOrEmpty(ss)) {
            queryWrapper.like(SmsTsWorkerLevel::getName, ss);
        }

        Page<SmsTsWorkerLevel> page = new Page<>(pageNum, pageSize);
        this.page(page, queryWrapper);
        List<SmsTsWorkerLevelResp> collect = page.getRecords().stream().map(item -> {
            SmsTsWorkerLevelResp resp = new SmsTsWorkerLevelResp();
            BeanUtils.copyProperties(item, resp);
            return resp;
        }).collect(Collectors.toList());

        return CommonResult.success(collect, (int) page.getTotal());
    }
}
